package com.interview.two.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.FileNotFoundException;

@Service
@Slf4j
public class Service6 {

   // @Resource
   // private Service6 proxy;

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void foo() throws FileNotFoundException {
        log.info("foo");
        // 使用这个前提是：@EnableAspectJAutoProxy(exposeProxy = true)
        ((Service6)AopContext.currentProxy()).bar();
        log.info("调用bar方法的类信息：{}", ((Service6)AopContext.currentProxy()).getClass());
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    public void bar() throws FileNotFoundException {
        log.error("bar");
    }
}
